#ifndef MP_HTTP_SEND_PROGRESS_CALLBACK_H
#define MP_HTTP_SEND_PROGRESS_CALLBACK_H

#include <string>
#include <iostream>
#include "mpLog.h"

class http_send_progress_callback
{
public:
    http_send_progress_callback(const std::string id)
        :_id(id)
    {
    }

    ~http_send_progress_callback(){
        std::cout << "delete http_send_progress_callback." << std::endl;
    }

    //int operator () (int a, int b) const
    void operator()(std::size_t step,
                    std::size_t current,
                    std::size_t total) const
    {
        if(step == 1){
            MPLOG_INFO << "[" << _id << "] " << "http connected";
        }
        else if(step == 2){
            if(total >0){
                long double tmp = (long double)current/(long double) total;
                tmp = roundl(tmp * 10000) / 100;
                MPLOG_INFO << "[" << _id << "] " << "http upload: " << tmp << " %";
            }
            else{
                MPLOG_INFO << "[" << _id << "] " << "http upload: " << current << " bytes";
            }
        }
        else if(step == 3){
            if(total == MP::HTTP::INVALID_SIZE || total == 0 ){
                 MPLOG_INFO << "[" << _id << "] " << "http read chunked data : " << current << " bytes";
            }
            else{
                long double tmp = (long double)current/(long double) total;
                 tmp = roundl(tmp * 10000) / 100;
                //auto tmp = roundl(current * 100 / total);
                 MPLOG_INFO << "[" << _id << "] " << "http download : " << tmp << " %";
            }
        }
    }

private:
    std::string _id;


};



#endif // MP_HTTP_SEND_PROGRESS_CALLBACK_H
